package com.ken.springcloud.controller;

import com.ken.springcloud.pojo.Dept;
import com.ken.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <ul>
 * <li>Title: DeptController</li>
 * <li>Description: TODO </li>
 * </ul>
 *
 * @author swc
 * @date 2021-08-25 16:12
 */
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    //这部分配合下面 部分 获取当前注册的服务相关信息
/*    @Autowired
    private DiscoveryClient discoveryClient;*/


    @PostMapping("/dept/add")
    public boolean addDept(@RequestBody Dept dept) {
        return deptService.addDept(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept queryById(@PathVariable("id") Long id) {
        return deptService.queryById(id);
    }

    @GetMapping("/dept/list")
    public List<Dept> queryAll() {
        return deptService.queryAll();
    }

/*    @GetMapping("/eureka/list")
    public Object getEurekaList(){
        List<String> services = discoveryClient.getServices();
        List<ServiceInstance> instances = discoveryClient.getInstances("SPRINGCLOUD-PROVIDER-DEPT");
        for (ServiceInstance instance : instances) {
            System.out.println(instance.getHost()+"\r\n"
            +instance.getPort()+"\r\n"
            +instance.getServiceId()+"\r\n"
            +instance.getUri()+"\r\n"
            );
        }
        return discoveryClient;
    }*/

}
